

package com.coding4play.mqtt.broker.protocol;

import com.coding4play.mqtt.common.repository.IDupPubRelMessageRepository;
import io.netty.channel.Channel;
import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader;
import io.netty.util.AttributeKey;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * PUBCOMP连接处理
 */
@Slf4j
@AllArgsConstructor
public class PubComp {

    private IDupPubRelMessageRepository dupPubRelMessageRepository;

    public void processPubComp(Channel channel, MqttMessageIdVariableHeader variableHeader) {
        int messageId = variableHeader.messageId();
        log.debug("PUBCOMP - clientId: {}, messageId: {}", channel.attr(AttributeKey.valueOf("clientId")).get(), messageId);
        dupPubRelMessageRepository.delete((String) channel.attr(AttributeKey.valueOf("clientId")).get(), variableHeader.messageId());
    }
}
